﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;
using Dao.Interface;
using NHibernate.Criterion;

namespace Dao
{
    public class UserInfoRepository : Repository<UserInfo>, IUserInfoRepository
    {
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="name">用户名</param>
        /// <returns></returns>
        public UserInfo Get(string name)
        {
            UserInfo userInfo = null;
            IList<UserInfo> list = this.Session.CreateCriteria(typeof(UserInfo)).Add(Restrictions.Eq("Name", name)).List<UserInfo>();
            foreach (UserInfo item in list)
            {
                userInfo = item;
            }
            return userInfo;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public UserInfo Get(string name, string password)
        {
            UserInfo userInfo = null;
            IList<UserInfo> list = this.Session.CreateCriteria(typeof(UserInfo)).Add(Restrictions.Eq("Name", name)).Add(Restrictions.Eq("Password",password)).List<UserInfo>();
            foreach (UserInfo item in list)
            {
                userInfo = item;
            }
            return userInfo;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="email">邮箱</param>
        /// <returns></returns>
        public UserInfo GetByEmail(string email)
        {
            UserInfo userInfo = null;
            IList<UserInfo> list = this.Session.CreateCriteria(typeof(UserInfo)).Add(Restrictions.Eq("Email", email)).List<UserInfo>();
            foreach (UserInfo item in list)
            {
                userInfo = item;
            }
            return userInfo;
        }

        /// <summary>
        /// 获取用户信息根据手机号码
        /// </summary>
        /// <param name="mobile">手机号码</param>
        /// /// <param name="userPwd">用户密码</param>
        /// <returns></returns>
        public UserInfo GetByMobile(string mobile, string userPwd)
        {
            UserInfo userInfo = null;
            IList<UserInfo> list = this.Session.CreateCriteria(typeof(UserInfo)).Add(Restrictions.Eq("Mobile", mobile)).Add(Restrictions.Eq("Password", userPwd)).List<UserInfo>();
            foreach (UserInfo item in list)
            {
                userInfo = item;
            }
            return userInfo;
        }
    }
}
